package 笔试.室友;

import java.util.*;

/**
 * @author:谢君臣
 * @Date:2021/7/13-15:15
 * @version:1.0
 * @function:
 */
public class gs1 {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String input = in.nextLine();
        String data = input.substring(1,input.length()-1);
        String[] split = data.split(",");
        Queue<Integer> queue = new ArrayDeque<Integer>();
        for (String s : split) {
            queue.add(Integer.parseInt(s));
        }
        System.out.println(Arrays.toString(getResult(queue)));
    }

    private static int[] getResult(Queue<Integer> queue) {
        int[] res = new int[queue.size()];
        int flag = 0,i = 0;
        while (queue.size()>0){
            int temp = queue.poll();
            if(charge(res,temp,i)){
                res[i]=temp;
                i++;
                flag=0;
            }else{
                flag++;
                queue.add(temp);
            }
            if (flag>=queue.size())
               return insert(res,queue);
        }
        return res;
    }

    private static int[] insert(int[] res, Queue<Integer> queue) {
        while (queue.size()>0){
            Integer data = queue.poll();
            int index = charge(res,data);
            if (index>=0){
                for (int i = res.length - 1; i > index; i--) {
                   res[i]=res[i-1];
                }
                res[index] = data;
            }else
                return new int[0];
        }
        return res;
    }

    private static boolean charge(int[] res, int temp, int i) {
        if (i==0) return true;
        else{
            return res[i-1]!=temp;
        }
    }
    private static int charge(int[] res, int temp) {
        int j = -1;
        for (int i = 1; i < res.length-1; i++) {
            if (res[i-1]!=temp&&res[i]!=temp)return i;
        }
        if (temp!=res[0])j=0;
        return j;
    }
}
